package gouhuo.allbugs.top.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gouhuo.allbugs.top.mapper.UserTeamMapper;
import gouhuo.allbugs.top.model.domain.User;
import gouhuo.allbugs.top.model.domain.UserTeam;
import gouhuo.allbugs.top.model.vo.TeamUserVO;
import gouhuo.allbugs.top.model.vo.UserVO;
import gouhuo.allbugs.top.service.UserService;
import gouhuo.allbugs.top.service.UserTeamService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 15294780204
 * @description 针对表【user_team(用户队伍关系)】的数据库操作Service实现
 * @createDate 2023-03-06 18:19:25
 */
@Service
public class UserTeamServiceImpl extends ServiceImpl<UserTeamMapper, UserTeam>
        implements UserTeamService {

    @Resource
    private UserService userService;

    @Override
    public List<TeamUserVO> teamDetail(String teamId) {
        List<UserTeam> userTeamList = list(new LambdaQueryWrapper<UserTeam>().eq(UserTeam::getTeamId, teamId).ne(UserTeam::getTies, 0));
        return userTeamList.stream().map(userTeam -> {
            TeamUserVO teamUserVO = new TeamUserVO();
            BeanUtils.copyProperties(userTeam, teamUserVO);
            UserVO userVO = new UserVO();
            User user = userService.getById(userTeam.getUserId());
            BeanUtils.copyProperties(user, userVO);
            if (userTeam.getTies() == 2) {
                teamUserVO.setCreateUser(userVO);
            } else {
                teamUserVO.setUser(userVO);
            }
            return teamUserVO;
        }).collect(Collectors.toList());
    }

}




